package org.xx.Iterator;

import java.util.List;

/**
 * 书架类
 */
public class BookShelf implements Aggregate{
    /**
     * 书的集合数组
     */
    private List<Book> books;

    /**
     * 最后一位索引
     */
    private int last = 0;

    /**
     * 构造函数
     */
    public BookShelf(List<Book> bookList) {
        this.books = bookList;
        this.last = books.size();
    }

    /**
     * 获取书本
     * @param index
     * @return
     */
    public Book getBook(int index) {
        return books.get(index);
    }

    /**
     * 添加书本
     * @param book
     */
    public void appendBook(Book book) {
        this.books.add(book);
        last++;
    }

    /**
     * 获取长度
     * @return
     */
    public int getLength() {
        return last;
    }


    @Override
    public Iterator iterator() {
        return new BookShelfIterator(this);
    }
}
